<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-wms__trkpost}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-input v-model="dataForm.contNo" placeholder="请输入托盘条码" maxlength="32" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle"
        style="width: 100%;" highlight-current-row>
        <el-table-column prop="trkId" label="指令id" header-align="center" align="center"></el-table-column>
        <el-table-column prop="requestPk" label="请求pk" header-align="center" align="center" min-width="130">
        </el-table-column>
        <el-table-column prop="contNo" label="托盘条码" header-align="center" align="center"></el-table-column>
        <el-table-column prop="trkPrty" label="优先级" header-align="center" align="center"></el-table-column>
        <el-table-column prop="trkType" label="任务类型" header-align="center" align="center"></el-table-column>
        <el-table-column prop="frmPos" label="起始点" header-align="center" align="center" min-width="130">
        </el-table-column>
        <el-table-column prop="toPos" label="目标点" header-align="center" align="center" min-width="130">
        </el-table-column>
        <el-table-column prop="curPos" label="当前位置" header-align="center" align="center" min-width="130">
        </el-table-column>
        <el-table-column prop="trkSt" label="任务状态" header-align="center" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.trkSt === 0">初始</el-tag>
            <el-tag v-else-if="scope.row.trkSt === 1" type="warning">已下发</el-tag>
            <el-tag v-else-if="scope.row.trkSt === 2" type="success">已完成</el-tag>
            <el-tag v-else type="danger">异常</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="isFull" label="空托盘" header-align="center" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.isFull === '0'">空框</el-tag>
            <el-tag v-else-if="scope.row.isFull === '1'">满载</el-tag>
            <el-tag v-else type="danger">未知</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="groupNo" label="任务组号" header-align="center" align="center"></el-table-column>
        <el-table-column prop="creator" label="创建用户" header-align="center" align="center"></el-table-column>
        <el-table-column prop="createDate" label="创建日期" header-align="center" align="center" min-width="155">
        </el-table-column>
        <el-table-column prop="updater" label="更新用户" header-align="center" align="center"></el-table-column>
        <el-table-column prop="updateDate" label="更新日期" header-align="center" align="center" min-width="155">
        </el-table-column>
        <el-table-column prop="comments" label="备注" header-align="center" align="center"></el-table-column>
        <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
          <template slot-scope="scope">
            <el-button v-if="$hasPermission('wms:trkpost:update')" type="text" size="small"
              @click="simulateDone(scope.row.trkId)">{{ $t("simulateDone") }}</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total"
        layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/wms/trkpost/page',
        getDataListIsPage: true,
        exportURL: '/wms/trkpost/export',
        deleteURL: '/wms/trkpost',
        deleteIsBatch: true
      },
      dataForm: {
        trkId: '',
        contNo: ''
      }
    }
  },
  methods: {
    simulateDone(id) {
      console.log("trkId:", id)
      this.$confirm(this.$t('prompt.info', { 'handle': this.$t('simulateDone') }), this.$t('prompt.title'), {
        confirmButtonText: this.$t('confirm'),
        cancelButtonText: this.$t('cancel'),
        type: 'warning'
      }).then(() => {
        this.$http.post(`/wms/trkpost/simulate/${id}`).then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg)
          }
          this.$message({
            message: res.msg,
            type: 'success',
            duration: 500,
            onClose: () => {
              this.query()
            }
          })
        }).catch(() => { })
      }).catch(() => { })
    }
  },
}
</script>
